/******************************************************************************
 *
 * Project:		SerwerSemaforow
 * File:		pinging_thread.cpp
 * Author:		karooolek
 * Created on:	2010-01-22
 *
 ******************************************************************************/

#include "pinging_thread.h"

PingingThread::PingingThread(float interval) :
	Thread(),
	_interval(interval), _conns()
{
}

PingingThread::~PingingThread()
{
}

void PingingThread::_run()
{
	InfoMessage pingMsg;
	pingMsg.type = MSG_PING;
	
	while(!_stop)
	{	
		// dla kazdego polaczenia
		for(std::list<Connection *>::iterator i = _conns.begin();
			i != _conns.end();
			++i)
		{
			Connection *conn  = *i;

			// wyslij ping
			conn->send((uint8 *)&pingMsg, sizeof(pingMsg));
		}

		// odpocznij przed nastepnym pinganiem
		_sleep(_interval);
	}
}

